package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.mapper.ApUserRealnameMapper;
import com.zhentao.model.common.dtos.PageResponseResult;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.user.dto.AuthDto;
import com.zhentao.model.user.pojo.ApUserRealname;
import com.zhentao.service.ApUserRealnameService;
import com.zhentao.service.ApUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ApUserRealnameServiceImpl implements ApUserRealnameService {
    @Autowired
    private ApUserRealnameMapper apUserRealnameMapper;
    @Override
    public ResponseResult list(AuthDto dto) {
        dto.checkParam();
        Page<ApUserRealname> page=new Page<>(dto.getPage(),dto.getSize());
        QueryWrapper<ApUserRealname> wrapper=new QueryWrapper<>();
        wrapper.lambda().eq(dto.getStatus() != null,ApUserRealname::getStatus, dto.getStatus());
        page=apUserRealnameMapper.selectPage(page,wrapper);
        PageResponseResult result=new PageResponseResult();
        result.setCurrentPage((int) page.getCurrent());
        result.setSize((int) page.getSize());
        result.setTotal((int) page.getTotal());
        result.setData(page.getRecords());
        result.setCode(200);
        return result;
    }

    @Override
    public ResponseResult authFail(AuthDto dto) {
        ApUserRealname apUserRealname=new ApUserRealname();
        apUserRealname.setId(dto.getId());
        apUserRealname.setStatus(2);
        apUserRealname.setReason(dto.getMsg());
        apUserRealnameMapper.updateById(apUserRealname);
        return ResponseResult.okResult(200,"修改成功");
    }

    @Override
    public ResponseResult authPass(AuthDto dto) {
        ApUserRealname apUserRealname=new ApUserRealname();
        apUserRealname.setStatus(9);
        apUserRealname.setId(dto.getId());
        apUserRealnameMapper.updateById(apUserRealname);
        return ResponseResult.okResult(200,"修改成功");
    }
}
